% Function solves the steady state of the greed model (Equation numbers are in Appendix 1.3.1)
function diff = solveGreedSS(vbar)
global beta thetabar alpha phi psi lambda 
wbar=alpha*thetabar*(1-vbar)^(alpha-1);             % 1. Definition of wages=MPL
p=psi*vbar^(1-1/phi)    ;                           % Probability of winning 
pprime=(1-1/phi)*psi*vbar^(-1/phi);                 % Probability of winning derivative
vbarW=lambda*thetabar/(1-beta);                     % 3. Value Fn of winning  (lambda-=1)
vbarL=(wbar*(1-vbar)+p*beta*vbarW)/(1-beta*(1-p));  % 4. Value Fn of losing (out of power)  (lambda-=1)  
FOCRHS=pprime*beta*(vbarW-vbarL);                   % 2. FOC RHS (Note: FOC LHS is the wage)
diff=wbar- FOCRHS ;                                 % Note: if the diff is positive it means that working is too attractive


